/**
 * Dark theme — data display (tables, KPIs, forms, modals)
 * Loaded after all page CSS to ensure readable text & surfaces on dark shells.
 */

/* ── Table surface tokens (dark shells) ───────────────────── */
body.theme-dark {
  --color-table-header-bg: color-mix(in srgb, var(--color-surface) 75%, var(--color-bg));
  --color-table-row-even: color-mix(in srgb, var(--color-surface) 88%, var(--color-bg));
  --color-table-row-hover: color-mix(in srgb, var(--color-primary) 14%, var(--color-surface));
  --color-table-sticky-bg: var(--color-surface);
  --color-panel-alt: color-mix(in srgb, var(--color-surface) 92%, var(--color-bg));
  --color-input-bg: color-mix(in srgb, var(--color-surface) 95%, var(--color-bg));
  --color-scrollbar-track: var(--color-bg);
  --color-scrollbar-thumb: var(--color-border);
}

/* ── Global tables ──────────────────────────────────────────── */
body.theme-dark .table thead,
body.theme-dark .table thead th {
  background: var(--fac-table-head-bg, var(--color-table-header-bg)) !important;
  color: var(--fac-table-head-text, #e2e8f0) !important;
}

body.theme-dark .table tbody tr:nth-child(even),
body.theme-dark .table tbody tr:nth-child(even) td {
  background: var(--color-table-row-even);
}

body.theme-dark .table tbody tr:hover,
body.theme-dark .table tbody tr:hover td {
  background: var(--color-table-row-hover);
}

body.theme-dark .table tbody td,
body.theme-dark .table tbody th {
  color: var(--color-text);
  border-bottom-color: var(--color-border);
}

/* ── IT master / compact tables ───────────────────────────── */
body.theme-dark .it-master-table-container .table tbody tr:nth-child(even),
body.theme-dark .it-master-table-container .table tbody tr:nth-child(even) td.actions {
  background: var(--color-table-row-even);
}

body.theme-dark .it-master-table-container .table tbody tr:hover,
body.theme-dark .it-master-table-container .table tbody tr:hover td.actions {
  background: var(--color-table-row-hover);
}

body.theme-dark .it-master-table-container .table th.actions,
body.theme-dark .it-master-table-container .table td.actions {
  background: var(--color-table-sticky-bg);
}

body.theme-dark .it-master-table-container .tbl-scroll-btn {
  background: color-mix(in srgb, var(--color-surface) 90%, transparent);
  border-color: var(--color-border);
  color: var(--color-text);
}

body.theme-dark .it-master-table-container .tbl-scroll-btn:hover {
  background: var(--color-surface);
}

body.theme-dark .table-compact thead th {
  background: var(--fac-table-head-bg, var(--color-table-header-bg)) !important;
  color: var(--fac-table-head-text, #e2e8f0) !important;
  box-shadow: none;
}

body.theme-dark .table-hover tbody tr:hover,
body.theme-dark .table-hover tbody tr:focus-within,
body.theme-dark table.table-hover tbody tr:hover,
body.theme-dark table.table-hover tbody tr:focus-within {
  background: var(--color-table-row-hover) !important;
}

body.theme-dark .table-hover tbody tr:hover td,
body.theme-dark .table-hover tbody tr:focus-within td,
body.theme-dark table.table-hover tbody tr:hover td,
body.theme-dark table.table-hover tbody tr:focus-within td {
  background: inherit !important;
  color: var(--color-text) !important;
}

/* ── Scrollbars in data areas ───────────────────────────────── */
body.theme-dark .table-container-scrollable::-webkit-scrollbar-track,
body.theme-dark .results-content-area::-webkit-scrollbar-track {
  background: var(--color-scrollbar-track);
  border-color: var(--color-border);
}

body.theme-dark .table-container-scrollable::-webkit-scrollbar-thumb,
body.theme-dark .results-content-area::-webkit-scrollbar-thumb {
  background: var(--color-scrollbar-thumb);
  border-color: var(--color-scrollbar-track);
}

body.theme-dark .table-container-scrollable::-webkit-scrollbar-corner {
  background: var(--color-scrollbar-track);
  border-color: var(--color-border);
}

/* ── KPI & summary data text ────────────────────────────────── */
body.theme-dark .kpi-label,
body.theme-dark .kpi-value,
body.theme-dark .reports-kpi-label,
body.theme-dark .reports-kpi-value,
body.theme-dark .monitor-kpi-label,
body.theme-dark .monitor-kpi-value,
body.theme-dark .borrow-kpi-label,
body.theme-dark .borrow-kpi-value,
body.theme-dark .it-kpi-label,
body.theme-dark .it-kpi-value,
body.theme-dark .summary-label,
body.theme-dark .summary-value,
body.theme-dark .summary-hint,
body.theme-dark .charts-summary-item .summary-label,
body.theme-dark .charts-summary-item .summary-value,
body.theme-dark .charts-summary-item .summary-hint {
  color: var(--color-text);
}

body.theme-dark .kpi-label,
body.theme-dark .reports-kpi-label,
body.theme-dark .monitor-kpi-label,
body.theme-dark .borrow-kpi-label,
body.theme-dark .it-kpi-label,
body.theme-dark .summary-label,
body.theme-dark .charts-summary-item .summary-label,
body.theme-dark .summary-hint,
body.theme-dark .charts-summary-item .summary-hint {
  color: var(--color-text-muted);
}

body.theme-dark .charts-summary-item {
  background: var(--color-panel-alt);
  border: 1px solid var(--color-border);
}

body.theme-dark .overall-summary-row > div {
  background: var(--color-panel-alt) !important;
  border: 1px solid var(--color-border);
}

/* ── Cards, panels, modals ──────────────────────────────────── */
body.theme-dark .chart-modal-content {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

body.theme-dark .chart-modal-title {
  color: var(--color-text);
}

body.theme-dark .chart-modal-close:hover {
  background: color-mix(in srgb, var(--color-text) 10%, transparent);
}

body.theme-dark .modal-content,
body.theme-dark .modal-header,
body.theme-dark .modal-body,
body.theme-dark .modal-footer {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

body.theme-dark .dropdown-menu {
  background: var(--color-surface);
  border-color: var(--color-border);
}

body.theme-dark .dropdown-item {
  color: var(--color-text);
}

body.theme-dark .dropdown-item:hover {
  background: var(--color-table-row-hover);
  color: var(--color-text);
}

/* ── Pagination ─────────────────────────────────────────────── */
body.theme-dark .pagination .page-link,
body.theme-dark .pagination-btn,
body.theme-dark .page-btn {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

body.theme-dark .pagination .page-link:hover,
body.theme-dark .pagination-btn:hover:not(:disabled),
body.theme-dark .page-btn:hover:not(:disabled) {
  background: var(--color-table-row-hover);
  color: var(--color-text);
}

body.theme-dark .pagination .page-item.active .page-link,
body.theme-dark .pagination-btn.active,
body.theme-dark .page-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

/* ── Forms & filters ────────────────────────────────────────── */
body.theme-dark select,
body.theme-dark textarea,
body.theme-dark input[type="text"],
body.theme-dark input[type="number"],
body.theme-dark input[type="email"],
body.theme-dark input[type="password"],
body.theme-dark input[type="date"],
body.theme-dark input[type="search"],
body.theme-dark input[type="tel"] {
  background: var(--color-input-bg);
  color: var(--color-text);
  border-color: var(--color-border);
}

body.theme-dark select option {
  background: var(--color-surface);
  color: var(--color-text);
}

body.theme-dark .filter-panel,
body.theme-dark .filters-card,
body.theme-dark .search-panel,
body.theme-dark .form-section,
body.theme-dark .wizard-step-content {
  background: var(--color-surface);
  border-color: var(--color-border);
}

body.theme-dark .form-label,
body.theme-dark label {
  color: var(--color-text-muted);
}

/* ── Status badges (dark-tinted, readable) ──────────────────── */
body.theme-dark .badge-status-active,
body.theme-dark .badge-success {
  background: color-mix(in srgb, #16a34a 22%, var(--color-surface));
  color: #86efac;
}

body.theme-dark .badge-status-damaged,
body.theme-dark .badge-danger {
  background: color-mix(in srgb, #dc2626 22%, var(--color-surface));
  color: #fca5a5;
}

body.theme-dark .badge-status-missing,
body.theme-dark .badge-warning {
  background: color-mix(in srgb, #d97706 22%, var(--color-surface));
  color: #fcd34d;
}

body.theme-dark .badge-status-repair,
body.theme-dark .badge-info {
  background: color-mix(in srgb, #2563eb 22%, var(--color-surface));
  color: #93c5fd;
}

body.theme-dark .badge-status-disposed,
body.theme-dark .badge-secondary,
body.theme-dark .badge-status-inactive {
  background: color-mix(in srgb, var(--color-text-muted) 18%, var(--color-surface));
  color: var(--color-text-muted);
}

/* ── Module CSS overrides (responsive / per-page) ───────────── */
body.theme-dark .electronics-table thead th,
body.theme-dark .electronics-table tbody tr:hover {
  background: var(--color-table-header-bg) !important;
}

body.theme-dark .electronics-table tbody tr:nth-child(even) {
  background: var(--color-table-row-even);
}

body.theme-dark .electronics-table tbody tr:hover {
  background: var(--color-table-row-hover) !important;
}

body.theme-dark .electronics-pagination .page-btn,
body.theme-dark .electronics-pagination button,
body.theme-dark .results-pagination button {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

body.theme-dark .electronics-pagination .page-btn:hover,
body.theme-dark .results-pagination button:hover {
  background: var(--color-table-row-hover);
}

body.theme-dark .kpi-card-mini,
body.theme-dark .dashboard-kpi-card,
body.theme-dark .stat-card {
  background: var(--color-surface);
  border-color: var(--color-border);
}

body.theme-dark .settings-table tbody tr:hover,
body.theme-dark .settings-master-table tbody tr:hover {
  background: var(--color-table-row-hover);
}

body.theme-dark .settings-table tbody tr:nth-child(even),
body.theme-dark .settings-master-table tbody tr:nth-child(even) {
  background: var(--color-table-row-even);
}

body.theme-dark .audit-scan-result,
body.theme-dark .scan-result-card,
body.theme-dark .asset-detail-panel {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

body.theme-dark .repair-card,
body.theme-dark .repair-detail-section,
body.theme-dark .monitor-card {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--color-text);
}

body.theme-dark .borrow-status-badge {
  border: 1px solid var(--color-border);
}

body.theme-dark .borrow-items-section,
body.theme-dark .borrow-form-card,
body.theme-dark .borrow-list-card {
  background: var(--color-surface);
  border-color: var(--color-border);
}

body.theme-dark .borrow-table tbody tr:nth-child(even) {
  background: var(--color-table-row-even);
}

body.theme-dark .borrow-table tbody tr:hover {
  background: var(--color-table-row-hover);
}

body.theme-dark .repair-filters-card,
body.theme-dark .it-repairs-dashboard:fullscreen,
body.theme-dark .it-repairs-dashboard:-webkit-full-screen,
body.theme-dark .it-repairs-dashboard:-ms-fullscreen {
  background: var(--color-bg);
}

body.theme-dark .info-card,
body.theme-dark .ticket-details-card,
body.theme-dark .timeline-card,
body.theme-dark .timeline-content-modern {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--color-text);
}

body.theme-dark .info-card-label,
body.theme-dark .detail-label {
  color: var(--color-text-muted);
}

body.theme-dark .info-card-value,
body.theme-dark .detail-value,
body.theme-dark .ticket-details-card .card-title {
  color: var(--color-text);
}

body.theme-dark .detail-description {
  background: var(--color-panel-alt);
  border-color: var(--color-border);
  color: var(--color-text);
}

body.theme-dark .it-filters-card,
body.theme-dark .it-table-card {
  background: var(--color-surface);
  border-color: var(--color-border);
}

body.theme-dark .filter-label,
body.theme-dark .pagination-info {
  color: var(--color-text-muted);
}

body.theme-dark .table-responsive thead th {
  background: var(--color-table-header-bg);
  color: var(--color-text-muted);
}

body.theme-dark .table-responsive tbody tr:hover {
  background: var(--color-table-row-hover);
}

body.theme-dark .alert-warning,
body.theme-dark .scan-warning-box {
  background: color-mix(in srgb, #f59e0b 18%, var(--color-surface));
  color: #fcd34d;
  border-color: color-mix(in srgb, #f59e0b 35%, var(--color-border));
}

body.theme-dark .status-radio input:checked + .status-found {
  background: color-mix(in srgb, #16a34a 22%, var(--color-surface));
  border-color: #22c55e;
  color: #86efac;
}

body.theme-dark .status-radio input:checked + .status-moved,
body.theme-dark .status-radio input:checked + .status-missing {
  background: color-mix(in srgb, #f59e0b 20%, var(--color-surface));
  border-color: #f59e0b;
  color: #fcd34d;
}

body.theme-dark .status-radio input:checked + .status-damaged {
  background: color-mix(in srgb, #dc2626 20%, var(--color-surface));
  border-color: #ef4444;
  color: #fca5a5;
}

body.theme-dark .status-moved,
body.theme-dark .status-missing,
body.theme-dark .status-damaged,
body.theme-dark .status-found {
  border-color: var(--color-border);
  color: var(--color-text);
}

/* ── DataTables / loading states ────────────────────────────── */
body.theme-dark .table-loading,
body.theme-dark .empty-state {
  color: var(--color-text-muted);
}

body.theme-dark .dataTables_wrapper .dataTables_info,
body.theme-dark .dataTables_wrapper .dataTables_length,
body.theme-dark .dataTables_wrapper .dataTables_filter {
  color: var(--color-text-muted);
}

body.theme-dark .dataTables_wrapper .dataTables_paginate .paginate_button {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

body.theme-dark .dataTables_wrapper .dataTables_paginate .paginate_button.current {
  background: var(--color-primary) !important;
  color: #fff !important;
}

/* ── Reports & charts view ──────────────────────────────────── */
body.theme-dark .reports-dashboard,
body.theme-dark .reports-chart-card,
body.theme-dark .chart-card,
body.theme-dark .charts-view-kpi-card {
  background: var(--color-surface);
  border-color: var(--color-border);
}

body.theme-dark .kpi-item {
  background: var(--color-surface);
  border-color: var(--color-border);
}

body.theme-dark .page-subtitle,
body.theme-dark .card-subtitle,
body.theme-dark .text-muted {
  color: var(--color-text-muted) !important;
}

body.theme-dark .card-title,
body.theme-dark .page-title,
body.theme-dark h1, body.theme-dark h2,
body.theme-dark h3, body.theme-dark h4 {
  color: var(--color-text);
}

/* ── Settings embedded table styles ─────────────────────────── */
body.theme-dark .it-master-table-container .table tbody tr:nth-child(even) {
  background: var(--color-table-row-even);
}

body.theme-dark .it-master-table-container .table tbody tr:hover {
  background: var(--color-table-row-hover);
}
